@use "../abstracts/mixins";

$dropdown-padding: 0.4rem;

.tippy-box[data-theme~="dropdown"] {
  border-radius: 15px;
  box-shadow: var(--dropdown-box-shadow);
  outline: none !important;
  backdrop-filter: var(--dropdown-backdrop-filter);
  max-width: unset !important;
  max-height: 75vh;
  overflow-y: auto;

  .tippy-content {
    display: flex;
    flex-direction: column;
    padding: 0;

    .jenkins-spinner {
      margin: 1rem;
    }
  }
}

.tippy-box[data-animation="dropdown"][data-state="hidden"] {
  opacity: 0;
  transform: scale(0.975);

  &[data-placement^="top"] {
    transform-origin: bottom;
    transform: translateY(10px) scale(0.975);
  }

  &[data-placement^="bottom"] {
    transform-origin: top;
    transform: translateY(-10px) scale(0.975);
  }
}

.jenkins-dropdown {
  display: flex;
  flex-direction: column;
  padding: $dropdown-padding;

  &--compact {
    > .jenkins-dropdown__item,
    > .jenkins-dropdown__disabled {
      padding: 0 0.6rem;
      min-height: 30px !important;
    }
  }

  &__filter {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--input-border);

    &-input {
      &:focus {
        outline: none;
      }

      width: 100%;
      border: none;
      color: var(--text-color-secondary);
      background-color: unset;
    }

    svg {
      margin-top: 2px;
    }
  }

  &__separator {
    position: relative;
    height: 0.125rem;
    margin: $dropdown-padding calc($dropdown-padding * -1);
    border: none;

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      background-color: var(--text-color-secondary);
      opacity: 0.1;
    }
  }

  &__heading {
    color: var(--text-color-secondary) !important;
    margin: $dropdown-padding 0.55rem;
    font-size: 0.8125rem;
    font-weight: 500;
    opacity: 0.8;

    &:not(:first-of-type) {
      margin-top: 1rem;
    }
  }

  &__placeholder {
    color: var(--text-color-secondary) !important;
    margin: $dropdown-padding 0.55rem;
    font-size: 0.8125rem;
    opacity: 0.8;
  }

  &__disabled {
    color: var(--text-color-secondary) !important;
    font-size: 0.8125rem;
    opacity: 0.8;
    display: inline-flex;
    align-items: center;
    margin: 0;
    cursor: default;
  }

  &__item {
    --item-background--hover: var(--button-background--hover);
    --item-background--active: var(--button-background--active);
    --item-box-shadow--focus: var(--button-box-shadow--focus);

    @include mixins.item;

    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    border: none;
    outline: none;
    margin: 0;
    padding: $dropdown-padding 1.75rem $dropdown-padding 0.6rem;
    font-size: 0.8125rem;
    font-weight: 450;
    text-decoration: none !important;
    background: transparent;
    color: var(--text-color) !important;
    border-radius: 0.66rem;
    cursor: pointer;
    min-height: 36px;
    white-space: nowrap;
    gap: 1.2ch;
    min-width: 180px;
    user-select: none;

    &__icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 1.125rem;
      height: 1.125rem;
      margin-right: 0.1rem;

      svg,
      img {
        width: 1.125rem;
        height: 1.125rem;
        color: inherit;
      }
    }

    &:disabled {
      pointer-events: none;
      opacity: 0.5;
      filter: saturate(0.6);
    }

    &[class*="color"] {
      background: transparent;
      color: var(--color) !important;

      &::before {
        background: currentColor !important;
        opacity: 0;
      }

      &::after {
        box-shadow: 0 0 0 0.66rem currentColor;
        opacity: 0;
      }

      &:hover {
        &::before {
          opacity: 0.15;
        }
      }

      &:active,
      &:focus {
        &::before {
          opacity: 0.2;
        }

        &::after {
          box-shadow: 0 0 0 0.33rem currentColor;
          opacity: 0.1;
        }
      }
    }

    &__badge {
      margin-left: auto;
      margin-right: -0.85rem;
    }

    &__chevron {
      position: absolute;
      top: 0;
      right: 0.125rem;
      bottom: 0;
      background: var(--text-color-secondary);
      width: 1rem;
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'%3E%3Ctitle%3EChevron Forward%3C/title%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144'/%3E%3C/svg%3E");
      mask-size: contain;
      mask-repeat: no-repeat;
      mask-position: center;
      opacity: 0.6;
    }
  }

  &:hover {
    .jenkins-dropdown__item--selected {
      background: transparent;
    }
  }
}

.jenkins-dropdown__item--selected {
  background: var(--item-background--hover);
  animation: pulse 1s ease-in-out forwards;

  @keyframes pulse {
    50% {
      background: var(--item-background--active);
    }
  }
}

.jenkins-overflow-button__ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  width: 1.4rem;
  height: 1.1rem;
  margin-inline: -0.1rem;

  span {
    min-width: 0.3125rem;
    min-height: 0.3125rem;
    border: 1px solid currentColor;
    border-radius: 50%;
  }
}
